package com.craftplay.dao;

import com.craftplay.model.UserTicket;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

@Mapper
public interface UserTicketMapper {
    @Delete({
        "delete from user_ticket",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

//    @Insert({
//        "insert into user_ticket (id, user_id, ",
//        "ticket, expired, ",
//        "status)",
//        "values (#{id,jdbcType=INTEGER}, #{userId,jdbcType=INTEGER}, ",
//        "#{ticket,jdbcType=VARCHAR}, #{expired,jdbcType=TIMESTAMP}, ",
//        "#{status,jdbcType=INTEGER})"
//    })
//    int insert(UserTicket record);

    @Insert({
            "insert into user_ticket (user_id, ",
            "ticket, expired, ",
            "status)",
            "values (#{userId,jdbcType=INTEGER}, ",
            "#{ticket,jdbcType=VARCHAR}, #{expired,jdbcType=TIMESTAMP}, ",
            "#{status,jdbcType=INTEGER})"
    })
    int insertUserTicket(UserTicket record);

    @InsertProvider(type=UserTicketSqlProvider.class, method="insertSelective")
    int insertSelective(UserTicket record);

    @Select({
        "select",
        "id, user_id, ticket, expired, status",
        "from user_ticket",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="user_id", property="userId", jdbcType=JdbcType.INTEGER),
        @Result(column="ticket", property="ticket", jdbcType=JdbcType.VARCHAR),
        @Result(column="expired", property="expired", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="status", property="status", jdbcType=JdbcType.INTEGER)
    })
    UserTicket selectByPrimaryKey(Integer id);


    @Select({
            "select",
            "id, user_id, ticket, expired, status",
            "from user_ticket",
            "where ticket = #{ticket,jdbcType=VARCHAR}"
    })
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
            @Result(column="user_id", property="userId", jdbcType=JdbcType.INTEGER),
            @Result(column="ticket", property="ticket", jdbcType=JdbcType.VARCHAR),
            @Result(column="expired", property="expired", jdbcType=JdbcType.TIMESTAMP),
            @Result(column="status", property="status", jdbcType=JdbcType.INTEGER)
    })
    UserTicket selectByTicket(String ticket);




    @UpdateProvider(type=UserTicketSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(UserTicket record);

    @Update({
        "update user_ticket",
        "set user_id = #{userId,jdbcType=INTEGER},",
          "ticket = #{ticket,jdbcType=VARCHAR},",
          "expired = #{expired,jdbcType=TIMESTAMP},",
          "status = #{status,jdbcType=INTEGER}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(UserTicket record);
}